@extends('layouts.prize')
@section('pageTitle', '编辑奖品')
@inject('storeService', 'App\App\Services\StorageService')
@section('style')
    <link rel="stylesheet" href="/css/admin/validform_style.css">
    <style>

        /*meiyun*/
        .mgud {
            margin: 20px auto;
        }

        .mgb10 {
            margin-bottom: 10px;
        }

        .mgr30 {
            margin-right: 30px;
        }

        .main-panel {
            overflow: auto;
        }

        .card form [class*="col-"]:first-child {
            padding: 0 6px;
        }

        .card form [class*="col-"]:last-child {
            padding: 0 6px;
        }

        .template-active-img img {
            width: 100%;
            height: auto;
            overflow: hidden;
        }

        .template-active-img .user-template-btn {
            position: absolute;
            bottom: 20px;
            left: 50%;
            margin-left: -22px;
        }

        .template-active-img .template-qrcode {
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            background: rgba(0, 0, 0, .5);
            display: none;
        }

        .template-active-img:hover .template-qrcode {
            display: block
        }
    </style>
@endsection
@section('content')
    {{--@component('components.web.sidemenu')@endcomponent--}}
    <div class="main-panel">
        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="content content-full-width">
                                <ul role="tablist" class="nav nav-tabs">
                                    <li class="gift-tab active" role="entity">
                                        <a href="#gift" data-toggle="tab"><i class="glyphicon glyphicon-gift"></i>
                                            实物</a>
                                    </li>
                                </ul>
                                <div class="tab-content">
                                    <div id="gift" class="tab-pane gift-tab-pane mrgud_10 active">
                                        <div class="row">
                                            <div class="col-md-12">
                                                <form id="wizardForm" class="form-horizontal" method="post" action=""
                                                      enctype="multipart/form-data">
                                                    {{ csrf_field() }}
                                                    <input type="hidden" value="{{$prizeInfo['id']}}"
                                                           name="data[prize][id]">
                                                    <input type="hidden" value="entity" name="data[prize][type_code]">
                                                    <input type="hidden" value="1" name="data[prize][resource]">
                                                    <div class="row">
                                                        <div class="col-xs-4 app">
                                                            <div class="phone-view">
                                                                <div class="app-view">
                                                                    <div class="app-mainC">
                                                                        <div class="app-alert">
                                                                            <div class="app-alert-input">
                                                                                <div class="app-alert-image">
                                                                                    <img src="/images/admin/promotion_default.png">
                                                                                </div>
                                                                                <div class="app-alert-title">
                                                                                    <div class="title-name">{{$prizeInfo['name']}}</div>
                                                                                    <div class="title-endtime">有效期:<span
                                                                                                class="title-endtime-span">{{$prizeInfo['expired_end']}}</span>
                                                                                    </div>
                                                                                </div>

                                                                            </div>
                                                                            <div class="app-alert-scene-word">
                                                                                <div class="app-alert-scene-text">
                                                                                    线下门店兑换（当面核销有效）
                                                                                </div>
                                                                                <div>兑奖地址:<span
                                                                                            class="title-sence-address">{{$prizeInfo['exchange_address']}}</span>
                                                                                </div>

                                                                            </div>
                                                                            <div class="app-alert-mail-word displayable">
                                                                                <div class="app-alert-mail-text">
                                                                                </div>
                                                                                <div class="app-alert-mail-recipientName app-mail-manname">
                                                                                    请输入收件人姓名
                                                                                </div>
                                                                                <div class="app-alert-mail-recipientName app-mail-tell">
                                                                                    请输入收件人手机号
                                                                                </div>
                                                                                <div class="app-alert-mail-address app-mail-address">
                                                                                    请输入邮寄地址
                                                                                </div>

                                                                            </div>

                                                                        </div>
                                                                        <div class="app-btn"></div>
                                                                        <div class="app-paper"></div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-xs-8">
                                                            <div class="row">
                                                                <div class="col-sm-12">
                                                                    <div class="form-group">
                                                                        <label class="col-sm-2 col-sm-offset-1 control-label">奖品名称</label>
                                                                        <div class="col-sm-7 col-sm-offset-1">
                                                                            <input class="form-control prize-mail-name"
                                                                                   type="text" name="data[prize][name]"
                                                                                   required="required" datatype="s1-20"
                                                                                   value="{{$prizeInfo['name']}}"
                                                                                   ajaxurl="/web/prize/checkName/{{$prizeInfo['id']}}">
                                                                            <div class="info"><span
                                                                                        class="Validform_checktip"></span><span
                                                                                        class="dec"><s class="dec1">&#9670;</s><s
                                                                                            class="dec2">&#9670;</s></span>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <label class="col-sm-2 col-sm-offset-1 control-label">有效时间</label>
                                                                        <div class="col-sm-7 col-sm-offset-1">
                                                                            <div class="row service-charges">
                                                                                <div class="col-md-5 service-charges-name service-charges-name-0"
                                                                                     style="padding-left: 15px;">
                                                                                    <input type="text"
                                                                                           placeholder="开始时间"
                                                                                           required=""
                                                                                           name="data[prize][expired_start]"
                                                                                           data-msg="请输入开始时间"
                                                                                           class="form-control datetimepicker mailstartdate"
                                                                                           datatype="*"
                                                                                           value="{{$prizeInfo['expired_start']}}">
                                                                                    <div class="info"><span
                                                                                                class="Validform_checktip"></span><span
                                                                                                class="dec"><s
                                                                                                    class="dec1">&#9670;</s><s
                                                                                                    class="dec2">&#9670;</s></span>
                                                                                    </div>
                                                                                </div>
                                                                                <div class="col-md-5 service-charges-remark service-charges-remark-0">
                                                                                    <input type="text"
                                                                                           placeholder="开始时间"
                                                                                           required=""
                                                                                           name="data[prize][expired_end]"
                                                                                           data-msg="请输入开始时间"
                                                                                           class="form-control datetimepicker mailenddate"
                                                                                           datatype="*"
                                                                                           value="{{$prizeInfo['expired_end']}}">
                                                                                    <div class="info"><span
                                                                                                class="Validform_checktip"></span><span
                                                                                                class="dec"><s
                                                                                                    class="dec1">&#9670;</s><s
                                                                                                    class="dec2">&#9670;</s></span>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <label class="col-sm-2 col-sm-offset-1 control-label">奖品库存</label>
                                                                        <div class="col-sm-7 col-sm-offset-1">
                                                                            <input class="form-control" type="number"
                                                                                   placeholder="最大为9999999"
                                                                                   required="required"
                                                                                   name="data[prize][stock_number]"
                                                                                   number="true"
                                                                                   max="9999999" datatype="n1-7"
                                                                                   value="{{$prizeInfo['stock_number']}}"
                                                                                   readonly="readonly">
                                                                            <div class="info"><span
                                                                                        class="Validform_checktip"></span><span
                                                                                        class="dec"><s class="dec1">&#9670;</s><s
                                                                                            class="dec2">&#9670;</s></span>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <label class="col-sm-2 col-sm-offset-1 control-label">兑奖方式</label>
                                                                        <div class="col-sm-7 col-sm-offset-1">
                                                                            {{--<label class="radio-inline">--}}
                                                                                {{--<input type="radio"--}}
                                                                                       {{--name="data[prize][exchange_method]"--}}
                                                                                       {{--class="senceprize"--}}
                                                                                       {{--value="0">--}}
                                                                                {{--现场兑奖--}}
                                                                            {{--</label>--}}
                                                                            <label class="radio-inline">
                                                                                <input type="radio"
                                                                                       name="data[prize][exchange_method]"
                                                                                       class="mailprize"
                                                                                       value="1">
                                                                                邮寄兑奖
                                                                            </label>
                                                                        </div>
                                                                    </div>
                                                                    {{--<div class="senceprize-input">--}}
                                                                        {{--<div class="form-group">--}}
                                                                            {{--<label class="col-sm-2 col-sm-offset-1 control-label">现场兑换地址</label>--}}
                                                                            {{--<div class="col-sm-7 col-sm-offset-1">--}}
                                                                                {{--<input class="form-control sence-prize-address"--}}
                                                                                       {{--type="text"--}}
                                                                                       {{--placeholder="请填写地址"--}}
                                                                                       {{--name="data[prize][exchange_address]"--}}
                                                                                       {{--ignore="ignore"--}}
                                                                                       {{--value="{{$prizeInfo['exchange_address']}}">--}}
                                                                                {{--<div class="info"><span--}}
                                                                                            {{--class="Validform_checktip"></span><span--}}
                                                                                            {{--class="dec"><s class="dec1">&#9670;</s><s--}}
                                                                                                {{--class="dec2">&#9670;</s></span>--}}
                                                                                {{--</div>--}}
                                                                            {{--</div>--}}
                                                                        {{--</div>--}}
                                                                    {{--</div>--}}

                                                                    {{--<div class="form-group">--}}
                                                                        {{--<label class="col-sm-2 col-sm-offset-1 control-label">奖品标签</label>--}}
                                                                        {{--<div class="col-sm-7 col-sm-offset-1">--}}
                                                                            {{--<textarea class="form-control" type="text"--}}
                                                                                      {{--name="data[prize][tag]">{{$prizeInfo['tag']}}</textarea>--}}
                                                                            {{--<div class="info"><span--}}
                                                                                        {{--class="Validform_checktip"></span><span--}}
                                                                                        {{--class="dec"><s class="dec1">&#9670;</s><s--}}
                                                                                            {{--class="dec2">&#9670;</s></span>--}}
                                                                            {{--</div>--}}
                                                                        {{--</div>--}}
                                                                    {{--</div>--}}
                                                                    <div class="form-group backgroundImg-container">
                                                                        <label class="col-sm-2 col-sm-offset-1 control-label">奖品图片</label>
                                                                        <div class="col-sm-7 col-sm-offset-1">
                                                                            <input type="file" name="upfile"
                                                                                   accept="image/gif,image/jpeg,image/png"
                                                                                   data-target="uploadBackgroundFile"
                                                                                   data-preview-file-type="text"
                                                                                   class="form-control fileInput"
                                                                                   value="{{$storeService->tomedia($prizeInfo['background_image'])}}"
                                                                                   title=""
                                                                                   data-for="data[prize][background_image]"
                                                                                   maxFileSize="200k"
                                                                            >
                                                                            <input type="hidden"
                                                                                   name="data[prize][background_image]"
                                                                                   value="{{$prizeInfo['background_image']}}">
                                                                            <div class="info"><span
                                                                                        class="Validform_checktip"></span><span
                                                                                        class="dec"><s class="dec1">&#9670;</s><s
                                                                                            class="dec2">&#9670;</s></span>
                                                                            </div>
                                                                            <span class="help-block">100*100像素，支持PNG、JPG格式，小于200KB</span>
                                                                        </div>
                                                                    </div>
                                                                    <div class="row">
                                                                        <div class="col-sm-9 col-sm-offset-2">
                                                                            <div class="panel panel-info">
                                                                                <div class="panel-heading">
                                                                                    <h3 class="panel-title">奖品赞助商信息</h3>
                                                                                </div>
                                                                                <div class="panel-body sponsor_panel">
                                                                                    @foreach($prizeInfo['sponsor'] as $sponsor)
                                                                                        <div class="sponsor_form">
                                                                                            <div class="row">
                                                                                                <div class="col-sm-12">
                                                                                                    <img src="/images/admin/delet_red.png"
                                                                                                         class="sponsor_delet pull-right mgb10 mgr30">
                                                                                                </div>
                                                                                                <div class="form-group">
                                                                                                    <label class="col-sm-3 control-label">赞助商信息</label>
                                                                                                    <div class="col-sm-8 ">
                                                                                                        <input class="form-control"
                                                                                                               type="text"
                                                                                                               name="data[sponsor][name][]"
                                                                                                               datatype="sponsor"
                                                                                                               value="{{$sponsor['name']}}">
                                                                                                        <div class="info"><span
                                                                                                                    class="Validform_checktip"></span><span
                                                                                                                    class="dec"><s
                                                                                                                        class="dec1">&#9670;</s><s
                                                                                                                        class="dec2">&#9670;</s></span>
                                                                                                        </div>
                                                                                                    </div>
                                                                                                </div>
                                                                                                <div class="form-group">
                                                                                                    <label class="col-sm-3 control-label">商家Logo</label>
                                                                                                    <div class="col-sm-8">
                                                                                                        <input type="file"
                                                                                                               name="upfile"
                                                                                                               accept="image/gif,image/jpeg,image/png"
                                                                                                               data-target="uploadLogoFile"
                                                                                                               data-preview-file-type="text"
                                                                                                               class="form-control fileInput"
                                                                                                               value="{{$storeService->tomedia($sponsor['logo'])}}"
                                                                                                               title=""
                                                                                                               data-for="data[sponsor][logo][]"
                                                                                                               maxFileSize="200k">
                                                                                                        <input type="hidden"
                                                                                                               name="data[sponsor][logo][]"
                                                                                                               value="{{$sponsor['logo']}}">
                                                                                                        <div class="info"><span
                                                                                                                    class="Validform_checktip"></span><span
                                                                                                                    class="dec"><s
                                                                                                                        class="dec1">&#9670;</s><s
                                                                                                                        class="dec2">&#9670;</s></span>
                                                                                                        </div>
                                                                                                        <span class="help-block">支持PNG、JPG格式，小于200KB</span>
                                                                                                    </div>
                                                                                                </div>
                                                                                                <div class="form-group">
                                                                                                    <label class="col-sm-3 control-label">曝光率</label>
                                                                                                    <div class="col-sm-7">
                                                                                                        <input class="form-control ptr"
                                                                                                               type="number"
                                                                                                               name="data[sponsor][percent][]"
                                                                                                               datatype="/^100$|^[0-9]{1,2}$/"
                                                                                                               errormsg="只能输入0~100的整数"
                                                                                                               value="{{$sponsor['percent']}}">
                                                                                                        <div class="info"><span
                                                                                                                    class="Validform_checktip"></span><span
                                                                                                                    class="dec"><s
                                                                                                                        class="dec1">&#9670;</s><s
                                                                                                                        class="dec2">&#9670;</s></span>
                                                                                                        </div>
                                                                                                    </div>
                                                                                                    <label class="col-sm-1 control-label ptl">%</label>
                                                                                                </div>
                                                                                            </div>
                                                                                        </div>
                                                                                    @endforeach
                                                                                    <div class="pull-center mgud">
                                                                                        <button type="button"
                                                                                                class="btn btn-info btn-wd btn-finish panel-sponsor-butten">
                                                                                            添加一个新的赞助商
                                                                                        </button>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>

                                                        </div>
                                                    </div>
                                                    <div class="footer pull-center">

                                                        <button type="submit"
                                                                class="btn btn-submit btn-info btn-fill btn-wd btn-finish sponsor_sur">
                                                            完成
                                                        </button>

                                                        <div class="clearfix"></div>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
@endsection
@section('script')
    <script src="/js/admin/Validform_v5.3.2_min.js"></script>
    <script src="/js/initValidform.js"></script>
    <script>
        console.log(1);
		$(document).ready(function () {
			$('.senceprize').click(function () {
				$('.senceprize-input').removeClass('displayable');
				$('.app-alert-mail-word').addClass('displayable');
				$('.app-alert-scene-word').removeClass('displayable');
			});
			$('.mailprize').click(function () {
				$('.app-alert-mail-word').removeClass('displayable');
				$('.senceprize-input').addClass('displayable');
				$('.app-alert-scene-word').addClass('displayable');
			});
			$('.panel-sponsor-butten').click(function () {
				var addObj = $(this).parent('.mgud');
				$.get('/web/prize/sponsor', function (res) {
					addObj.before(res);
					var fileInputObj = addObj.prev('.sponsor_form').find('input[type=file]');
					initFileInput(fileInputObj);
					var deleteBtn = addObj.prev('.sponsor_form').find('.sponsor_delet');
					deleteBtn.click(function () {
						$(this).parents('.sponsor_form').remove();
					})
				});
			});
			$('.sponsor_delet').on('click', function () {
				$(this).parents('.sponsor_form').remove();
			});
			$('.prize-mail-name').blur(function () {
				if ($('.prize-mail-name').val() == '') {
					$('.title-name').empty();
					$('.title-name').html('活动名称');
				}
			});
			$('.prize-mail-name').on('input', function () {
				$('.title-name').empty();
				var name = $('.prize-mail-name').val();
				$('.title-name').html(name);
			});

			$('.mailenddate').on('input', function () {
				var enddate = $(this).val();
				$('.title-endtime-span').html(enddate);
			});


			$('.sence-prize-address').blur(function () {
				if ($('.sence-prize-address').val() == '') {
					$('.title-sence-address').empty();
					$('.sence-prize-address').attr('placeholder', '请填写地址');
				}
			});
			$('.sence-prize-address').on('input', function () {
				$('.title-sence-address').empty();
				var name = $('.sence-prize-address').val();
				$('.title-sence-address').html(name);
			});
			$('input[value="{{$prizeInfo['exchange_method']}}"]').prop('checked', 'checked').click();
			if ('{{$prizeInfo['exchange_method']}}' == 0) {
				$('input[value="0"]').prop('checked', 'checked');
			} else {
				$('input[value="1"]').prop('checked', 'checked');
				$('.senceprize').click();
			}

			$('.fileInput').each(function () {
				initFileInput($(this));
			});

			$(".datetimepicker").datetimepicker({format: 'YYYY-MM-DD hh:mm:ss'});

			initValidform($('#wizardForm'));
		})
    </script>
@endsection